package com.zlp.member.service.impl;

import com.zlp.common.base.BaseApiService;
import com.zlp.common.base.BaseResponse;
import com.zlp.common.constants.Econstants;
import com.zlp.common.core.bean.BeanToUtils;
import com.zlp.member.dao.UserDoMapper;
import com.zlp.member.entity.UserDo;
import com.zlp.member.output.dao.UserOutDTO;
import com.zlp.member.service.MemberService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 微服务电商项目
 *
 * @Description:
 * @CreateDate: Created in 2019/3/25 16:56
 * @Author: zouliping
 */
@RestController
public class MemberServiceImpl extends BaseApiService<UserOutDTO> implements MemberService {
     @Autowired
     private UserDoMapper userMapper;

    @Override
    public BaseResponse<UserOutDTO> existMobile(String mobile) {
        // 1.验证参数
        if (StringUtils.isEmpty(mobile)) {
            return setResultError("手机号码不能为空!");
        }
        // 2.根据手机号码查询用户信息 单独定义code 表示是用户信息不存在把
        Map<String,Object> parmMap = new HashMap<>();
        parmMap.put("mobile",mobile);
        UserDo user = userMapper.whereByBizKey(parmMap);
        if (user == null) {
            return setResultError(Econstants.HTTP_RES_CODE_EXISTMOBILE_203, "用户信息不存在!");
        }
        // 3.将do转换成dto
        return setResultSuccess(BeanToUtils.doToDto(user, UserOutDTO.class));
    }
}
